from PyQt5.QtCore import QObject, QUrl
from PyQt5.QtWebChannel import QWebChannel
from PyQt5.QtWebEngineWidgets import QWebEngineView



class WindowManager(QObject):
    def __init__(self):

        self.windows = {
            "main":None,
            "config":None
        }

        self.window_urls = {
            "login":"file:///Users/momo/PycharmProjects/walala-client/ui/html/login.html",
            "main":"file:///Users/momo/PycharmProjects/walala-client/ui/html/main.html",
            "config":"file:///Users/momo/PycharmProjects/walala-client/ui/html/config.html"
        }

    def createWindow(self,name,channel):
        view = QWebEngineView()

        if name == 'login':
            view.setFixedWidth(300)
            view.setFixedHeight(400)
            #channel = QWebChannel()
            #from action.loginAction import LoginAction
            #loginAction = LoginAction()
            #channel.registerObject('loginObject', loginAction)
            view.page().setWebChannel(channel)
            view.load(QUrl(self.window_urls.get(name)))



        (self.windows)[name] = view

    def showWindow(self,name):
        window = self.windows.get(name)
        window.show()

    def closeWindow(self,name):
        (self.windows)[name].close()


    def createLogin(self):
        view = QWebEngineView()
        view.setFixedWidth(300)
        view.setFixedHeight(400)

        channel = QWebChannel()
        from action.loginAction import LoginAction
        loginAction = LoginAction()
        channel.registerObject('loginObject', loginAction)
        view.page().setWebChannel(channel)

        view.load(QUrl('file:///Users/momo/PycharmProjects/walala-client/ui/html/login.html'))
        view.show()